package com.lifang.test6;

import com.lifang.framework.annotation.beans.Component;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Slf4j
@Aspect
@Component
public class AopAspect {

    @Before("execution(* com.lifang.test6.UserService.*(..))")
    public void before() {
        log.info("beforeAdvice.................");
    }

    @After("execution(* com.lifang.test6.UserService.*(..))")
    public void after() {
        log.info("afterAdvice..................");
    }

    @Around("execution(* com.lifang.test6.UserService.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        log.info("aroundBeforeAdvice...........{}.{} ", joinPoint.getTarget().getClass(), joinPoint.getSignature().getName());
        Object proceed = joinPoint.proceed();
        log.info("aroundAfterAdvice............方法执行耗时{}ms", System.currentTimeMillis() - start);
        return proceed;
    }

    @AfterReturning(value = "execution(* com.lifang.test6.UserService.*(..))", returning = "returnValue")
    public void afterRetuning(Object returnValue) {
        log.info("afterRetuningAdvice..........{}", returnValue);
    }

    @AfterThrowing(value = "execution(* com.lifang.test6.UserService.*(..))", throwing = "throwable")
    public void afterThrowing(Throwable throwable) {
        log.error("afterThrowing............", throwable);
    }

}
